@{
    ViewData["Title"] = "会员管理";
    Layout = "~/Areas/Manager/Views/Shared/_Layout.cshtml";
}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">会员信息</div>
                <div class="layui-card-body">
                    <div class="layui-form">
                        <div class="layui-row">
                            <div class="layui-form-item">
                                <div class="layui-col-md3" style="padding-left:0">
                                    <div class="input-group">
                                        <input type="text" id="keyWords" name="keyWords" placeholder="请输入用户名称" autocomplete="off" class="layui-input">
                                        <span class="input-group-btn">
                                            <button class="layui-btn" id="search">
                                                <i class="layui-icon layui-icon-search"></i>
                                            </button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-btn-container">
                            <div class="layui-btn-group">
                                <button class="layui-btn layui-btn-sm" id="StartUsing"><i class="layui-icon layui-icon-ok"></i>启用</button>
                                <button class="layui-btn layui-btn-sm layui-btn-danger" id="Forbidden"><i class="layui-icon layui-icon-close"></i>禁用</button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <table class="layui-table " lay-data="{page:true, id:'list'}" lay-filter="list">
                            <thead>
                                <tr>
                                    <th lay-data="{checkbox:true, fixed: true,style:'height:80px;'}"></th>
                                    <th lay-data="{ field: 'userId',width:80}">用户Id</th>
                                    <th lay-data="{ field: 'gravatar',templet:'#gravatar',style:'height:80px;padding:0 0',width:140}">用户头像</th>
                                    <th lay-data="{ field: 'userName',width:130}">用户名</th>
                                    <th lay-data="{ field: 'trueName',width:130}">姓名</th>
                                    <th lay-data="{ field: 'sex',templet:'#sex',align:'center',width:100}">性别</th>
                                    <th lay-data="{ field: 'points',width:100}">积分</th>
                                    <th lay-data="{ field: 'balance',width:100}">余额</th>
                                    <th lay-data="{ field: 'createDate',width:200}">注册时间</th>
                                    <th lay-data="{ field: 'activity',templet:'#activity',width:90}">状态</th>
                                    <th lay-data="{toolbar:'#tableoption'}">操作</th>
                                </tr>
                            </thead>
                        </table>
                        <script type="text/html" id="activity">
                            {{#  if(d.activity==true){  }}
                            <span class="layui-badge layui-bg-green">启用</span>
                            {{#  } else if(d.activity==false){ }}
                            <span class="layui-badge layui-bg-red">禁用</span>
                            {{#  } }}
                        </script>
                        <script type="text/html" id="gravatar">
                            {{#  if(d.gravatar.indexOf("http")!=-1){  }}
                            <div style="height:65px;"><img src="{{ d.gravatar }}" /></div>
                            {{#  } else if(d.gravatar.length<1){ }}
                            <div style="height:65px;"></div>
                            {{#  }else { }}
                            <div style="height:65px;"><img src="@BaseConfig.ImagesDoMain{{ d.gravatar }}" /></div>
                            {{#  } }}
                        </script>
                        <script type="text/html" id="tableoption">
                            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="info"><i class="layui-icon">&#xe63c;</i>查看</a>
                        </script>
                        <script type="text/html" id="sex">
                            {{#  if(d.sex=='男'){  }}
                            <input type="checkbox" name="sex" checked value="{{d.userId}}" lay-skin="switch" lay-filter="switchSex" lay-text="男|女">
                            {{#  } else { }}
                            <input type="checkbox" name="sex" value="{{d.userId}}" lay-skin="switch" lay-filter="switchSex" lay-text="男|女">
                            {{#  } }}
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<style>
    .layui-table-cell{
        height:100%
    }
</style>
@section scriptsfeet
{
<script type="text/javascript">
        layui.config({
            base: '/layuiadmin/' //自定义模块路径
        }).use(['sykjwh', 'table','form'], function () {
            var $ = layui.$, sykjwh = layui.sykjwh, table = layui.table,form=layui.form;

            //绑定数据
            sykjwh.dataBind('@Url.Action("List", "Member", new { area = Constant.AREAMANAGER })');

            //启用
            $("#StartUsing").click(function () {
                sykjwh.batOperate('@Url.Action("StartUsing", "Member", new { area = Constant.AREAMANAGER })', 'userId');
            });

            //禁用
            $("#Forbidden").click(function () {
                console.log("--------");
                sykjwh.batOperate('@Url.Action("Forbidden", "Member", new { area = Constant.AREAMANAGER })', 'userId');
            });

            form.on('switch(switchSex)', function (data) {
                //获取id值
                console.log(data.value + "----"); //开关value值，也可以通过data.elem.value得到
                var sex=this.checked?'男':'女'; 
                sykjwh.request("@Url.Action("SexEdit", "Member", new { area = Constant.AREAMANAGER })?userId=" + data.value + "&sex=" + sex,'POST');
            }); 

            //监听表格行
            table.on('tool(list)', function (obj) {
                var data = obj.data;//获得当前行数据
                if (obj.event === 'info') {
                    sykjwh.openFull('用户详情', '@Url.Action("Info", "Member", new { area = Constant.AREAMANAGER })/' + data.userId);
                } 
            });

            //搜索
            $("#search").click(function () {
                //绑定数据
                sykjwh.dataBind('@Url.Action("List", "Member", new { area = Constant.AREAMANAGER })', {
                    keyWords: $.trim($("#keyWords").val())
                });
            });
        });
</script>
}